package com.drug.controller;

import com.drug.domain.Result;
import com.drug.domain.Supplier;
import com.drug.mapper.SupplierMapper;
import com.drug.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SupplierController  {
    @Autowired
    private SupplierService supplierService;
    @Autowired
    private SupplierMapper supplierMapper;

    //多条件查询
    @ResponseBody
    @RequestMapping("/selectSupplier")
    public List<Supplier> deleteSupplier(Supplier supplier){
        List<Supplier> suppliers = supplierService.selectSupplier(supplier);
        return suppliers;
    }
    //分页查询
    @RequestMapping("/selectSupplierAll")
    @ResponseBody
    public Result pageSupplierFindAll(@RequestParam(required=true,defaultValue="1")Integer pageNum){
        return supplierService.pageSupplierFindAll(pageNum);
    }
    //逻辑删除
    @ResponseBody
    @RequestMapping("/deleteSupplier")
    public String deleteSupplier(Integer surId){
        supplierService.deleteSupplier(surId);
        return "drug supplier";
    }
    //增加

    @ResponseBody
    @RequestMapping("/insertSupplier")
    public void insertSupplier( Supplier supplier ){
        supplierService.insertSupplier(supplier);
    }

    //回显搜索
    @ResponseBody
    @RequestMapping("/selectSupplierById")
    public Supplier selectSupplierById(String surId){
        Supplier supplier = supplierMapper.selectSupplierById(Integer.valueOf(surId));
        System.err.println(supplier);
        return supplier;
    }
    //修改
    @ResponseBody
    @RequestMapping("/updateSupplier")
    public List<Supplier> updateSupplier(Supplier supplier){
        System.err.println(supplier);
        return  supplierService.updateSupplier(supplier);
    }
    @ResponseBody
    @RequestMapping("/findsuppliername")
    public Result findUsername1(String surName){
        return supplierService.selectSupplier1(surName);
    }
}
